package com.hdy.web.controller;

import com.hdy.web.dao.UserMapper;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class SignupController {
    final UserMapper userMapper;
    public SignupController(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @RequestMapping("/user/signup")
    public String insert(@RequestParam("studentNo") String studentNo, @RequestParam("institute") String institute,
                         @RequestParam("grade") String grade, @RequestParam("clazz") String clazz, @RequestParam("name") String name,
                         @RequestParam("username") String username, @RequestParam("password") String password, Model model){

        try {
             userMapper.insertUser(studentNo,institute, grade,clazz,name,username,password);
        } catch (Exception e) {
            model.addAttribute("msg","用户已存在！请重新注册！");
            return "index";
            }
                model.addAttribute("msg2","注册成功！请登录！");
        return "index";
    }
}
